import request from '@/utils/request'
// import storage from 'store'

const mainApi = {
  outApi: '/api/v1/outApi',
  openDir: '/api/v1/example/openLocalDir',
  uploadFile: '/api/v1/example/uploadFile',
  uploadFile: '/api/v1/example/welcome',
  executeJS: '/api/v1/example/executeJS',
  setShortcut: '/api/v1/example/setShortcut',
  autoLaunchEnable: '/api/v1/example/autoLaunchEnable',
  autoLaunchDisable: '/api/v1/example/autoLaunchDisable',
  autoLaunchIsEnabled: '/api/v1/example/autoLaunchIsEnabled',
  getOrderList: '/api/v1/hande/getOrderList',
  printOrder: '/api/v1/hande/printOrder',
  checkPrinter: '/api/v1/hande/checkPrinter',
  printAttachment: '/api/v1/hande/printAttachment',
  getPrinterList: '/api/v1/hande/getPrinterList',
  getPrinterInfo: '/api/v1/hande/getPrinterInfo',
  getUserSetting: '/api/v1/hande/getUserSetting',
  setUserSetting: '/api/v1/hande/setUserSetting',
}
export function setUserSetting(payload) {
  return request({
    url: mainApi.setUserSetting,
    method: 'post',
    data: payload
  })
}


export function getUserSetting() {
  return request({
    url: mainApi.getUserSetting,
    method: 'get'
  })
}

/**
 * 获取打印机信息
 * command
 * "usage": "https://localhost:8081/status/usage/",
  "consumable": "https://localhost:8081/status/consumable/",
  "devices": "https://localhost:8081/devices",
  "status": "https://localhost:8081/status/device/",
  "media": "https://localhost:8081/status/media/",
 */
export function getPrinterInfo(command, portName) {
  return request({
    url: mainApi.getPrinterInfo,
    method: 'get',
    params: {
      command: command,
      portName: portName
    }
  })
}


/**
 * 获取打印机列表
 */
export function getPrinterList() {
  return request({
    url: mainApi.getPrinterList,
    method: 'get',
  })
}


/**
 * 检测打印机状态
 */
export function checkPrinter(portName) {
  return request({
    url: mainApi.checkPrinter,
    method: 'get',
    params: {
      portName: portName
    }
  })
}

/**
 * 冲减打印信息
 */
export function printAttachment(attachmentList) {
  return request({
    url: mainApi.printAttachment,
    method: 'post',
    data: {
      "attachmentList": attachmentList
    }
  })
}
/**
 * 冲减打印信息
 */
export function printOrder(params) {
  return request({
    url: mainApi.printOrder,
    method: 'post',
    data: {
      "shipOrderId": params.shipOrderId
    }
  })
}


/**
 * 获取订单信息
 */
export function getOrderList(params) {
  return request({
    url: mainApi.getOrderList,
    method: 'post',
    data: {
      "RequestInfo": {
        "New_Name": params.orderId
      }
    }
  })
}


/**
 * outApi
 */
export function outApi(uri, parameter) {
  return request({
    url: mainApi[uri],
    method: 'post',
    data: parameter
  })
}

/**
 * local api
 */
export function localApi(uri, parameter) {
  return request({
    url: mainApi[uri],
    method: 'post',
    data: parameter
  })
}


/**
 * openDir
 */
export function welcome(parameter) {
  return request({
    url: mainApi.welcome,
    method: 'post',
    data: parameter
  })
}


/**
 * openDir
 */
export function openDir(parameter) {
  return request({
    url: mainApi.openDir,
    method: 'post',
    data: parameter
  })
}

/**
 * uploadFile
 */
export function uploadFile(parameter) {
  return request({
    url: mainApi.uploadFile,
    method: 'post',
    data: parameter
  })
}

/**
 * executeJS
 */
export function executeJS(parameter) {
  return request({
    url: mainApi.executeJS,
    method: 'post',
    data: parameter
  })
}